package com.ruoyi.mq.listener;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.mq.service.serviceImpl.MessageProcessorContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 接收消息监听类
 * MQ消息消费者
 * @author japhet_jiu
 * @version 1.0
 */
@Component
@EnableRabbit
@Slf4j
public class ReceiveMsgListener {

    @Autowired
    private MessageProcessorContext context;
    //监听器监听指定的Queue
    @RabbitListener(queues= "${topic.destination}")
    public void process(Message message,String msg) {
//        MessageProperties messageProperties = message.getMessageProperties();
//        String contentType = messageProperties.getContentType();

//        if(true){
//            return;
//        }
        JSONObject result = JSONObject.parseObject(msg);
        // 使用
        context.processMessage(result);
        System.out.println("Receive-topic_queue1:"+result);
    }
}
